package com.geeklan.smart.ui.dialog;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;

import androidx.appcompat.content.res.AppCompatResources;

import com.geeklan.smart.R;
import com.geeklan.smart.databinding.LayoutSelectPetSexBinding;
import com.geeklan.smart.databinding.LayoutSelectPetWeightBinding;
import com.geeklan.smart.utils.DensityUtils;

public class PetSexBottomSheetDialog extends BaseBottomSheetDialog<LayoutSelectPetSexBinding> implements View.OnClickListener {
    public PetSexBottomSheetDialog(Context context) {
        super(context);
    }
    private int petSex = 1;
    @Override
    protected LayoutSelectPetSexBinding createContentViewBinding(LayoutInflater inflater) {
        return LayoutSelectPetSexBinding.inflate(inflater);
    }

    @Override
    protected void setupDialog() {
        super.setupDialog();
        setDialogTitle(R.string.pet_edit);
        setNonFullScreen(0.45f);
        mBinding.llGG.setOnClickListener(this);
        mBinding.llGGNotJJ.setOnClickListener(this);
        mBinding.llMM.setOnClickListener(this);
        mBinding.llMMNeuter.setOnClickListener(this);
        setConfirmButtonVisible(true);
        setConfirmButtonClickListener(v -> {
            dismiss();
            onBackListener.callback(petSex);
        });
    }


    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == mBinding.llGG.getId()) {
            petSex = 1;
            sexSelected(0);
        } else if (id == mBinding.llGGNotJJ.getId()) {
            petSex = 3;
            sexSelected(1);
        } else if (id == mBinding.llMM.getId()) {
            petSex = 2;
            sexSelected(2);
        } else if (id == mBinding.llMMNeuter.getId()) {
            petSex = 4;
            sexSelected(3);
        }
    }
    
    private OnBackListener onBackListener;

    public void setOnBackListener(OnBackListener onBackListener) {
        this.onBackListener = onBackListener;
    }

    public interface OnBackListener {
        void callback(int petSex);
    }
    private void sexSelected(int index) {
        if (index == 0) {
            mBinding.llGG.setBackground(AppCompatResources.getDrawable(mContext, R.drawable.layout_2773ff_radius_5_bg));
            mBinding.llGGNotJJ.setBackground(AppCompatResources.getDrawable(mContext, R.drawable.layout_f5_radius_5_bg));
            mBinding.llMM.setBackground(AppCompatResources.getDrawable(mContext, R.drawable.layout_f5_radius_5_bg));
            mBinding.llMMNeuter.setBackground(AppCompatResources.getDrawable(mContext, R.drawable.layout_f5_radius_5_bg));
            mBinding.ivGG.setImageResource(R.drawable.ic_gg);
            mBinding.ivGGNotJJ.setImageResource(R.drawable.ic_gg_def);
            mBinding.ivMM.setImageResource(R.drawable.ic_mm_def);
            mBinding.ivMMNeuter.setImageResource(R.drawable.ic_mm_def);
            mBinding.tvGG.setTextColor(mContext.getColor(R.color.color_2773FF));
            mBinding.tvGGNotJJ.setTextColor(mContext.getColor(R.color.color_999999));
            mBinding.tvMM.setTextColor(mContext.getColor(R.color.color_999999));
            mBinding.tvMMNeuter.setTextColor(mContext.getColor(R.color.color_999999));
        } else if (index == 1) {
            mBinding.llGG.setBackground(AppCompatResources.getDrawable(mContext, R.drawable.layout_f5_radius_5_bg));
            mBinding.llGGNotJJ.setBackground(AppCompatResources.getDrawable(mContext, R.drawable.layout_2773ff_radius_5_bg));
            mBinding.llMM.setBackground(AppCompatResources.getDrawable(mContext, R.drawable.layout_f5_radius_5_bg));
            mBinding.llMMNeuter.setBackground(AppCompatResources.getDrawable(mContext, R.drawable.layout_f5_radius_5_bg));
            mBinding.ivGG.setImageResource(R.drawable.ic_gg_def);
            mBinding.ivGGNotJJ.setImageResource(R.drawable.ic_gg);
            mBinding.ivMM.setImageResource(R.drawable.ic_mm_def);
            mBinding.ivMMNeuter.setImageResource(R.drawable.ic_mm_def);
            mBinding.tvGG.setTextColor(mContext.getColor(R.color.color_999999));
            mBinding.tvGGNotJJ.setTextColor(mContext.getColor(R.color.color_2773FF));
            mBinding.tvMM.setTextColor(mContext.getColor(R.color.color_999999));
            mBinding.tvMMNeuter.setTextColor(mContext.getColor(R.color.color_999999));
        } else if (index == 2) {
            mBinding.llGG.setBackground(AppCompatResources.getDrawable(mContext, R.drawable.layout_f5_radius_5_bg));
            mBinding.llGGNotJJ.setBackground(AppCompatResources.getDrawable(mContext, R.drawable.layout_f5_radius_5_bg));
            mBinding.llMM.setBackground(AppCompatResources.getDrawable(mContext, R.drawable.layout_ff378c_radius_5_bg));
            mBinding.llMMNeuter.setBackground(AppCompatResources.getDrawable(mContext, R.drawable.layout_f5_radius_5_bg));
            mBinding.ivGG.setImageResource(R.drawable.ic_gg_def);
            mBinding.ivGGNotJJ.setImageResource(R.drawable.ic_gg_def);
            mBinding.ivMM.setImageResource(R.drawable.ic_mm);
            mBinding.ivMMNeuter.setImageResource(R.drawable.ic_mm_def);
            mBinding.tvGG.setTextColor(mContext.getColor(R.color.color_999999));
            mBinding.tvGGNotJJ.setTextColor(mContext.getColor(R.color.color_999999));
            mBinding.tvMM.setTextColor(mContext.getColor(R.color.color_ff378c));
            mBinding.tvMMNeuter.setTextColor(mContext.getColor(R.color.color_999999));
        } else if (index == 3) {
            mBinding.llGG.setBackground(AppCompatResources.getDrawable(mContext, R.drawable.layout_f5_radius_5_bg));
            mBinding.llGGNotJJ.setBackground(AppCompatResources.getDrawable(mContext, R.drawable.layout_f5_radius_5_bg));
            mBinding.llMM.setBackground(AppCompatResources.getDrawable(mContext, R.drawable.layout_f5_radius_5_bg));
            mBinding.llMMNeuter.setBackground(AppCompatResources.getDrawable(mContext, R.drawable.layout_ff378c_radius_5_bg));
            mBinding.ivGG.setImageResource(R.drawable.ic_gg_def);
            mBinding.ivGGNotJJ.setImageResource(R.drawable.ic_gg_def);
            mBinding.ivMM.setImageResource(R.drawable.ic_mm_def);
            mBinding.ivMMNeuter.setImageResource(R.drawable.ic_mm);
            mBinding.tvGG.setTextColor(mContext.getColor(R.color.color_999999));
            mBinding.tvGGNotJJ.setTextColor(mContext.getColor(R.color.color_999999));
            mBinding.tvMM.setTextColor(mContext.getColor(R.color.color_999999));
            mBinding.tvMMNeuter.setTextColor(mContext.getColor(R.color.color_ff378c));
        }
    }

}
